package org.xvdb.services;

import java.math.BigInteger;

import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.xvdb.entities.POCEntity;

 
@Stateful
@Path(value = "/pocservice")
public class POCService {

    @PersistenceContext(unitName = "pocPersistenceUnit")
    private EntityManager em;
	
	@GET
	@Path(value = "/helloworld")
	@Produces({MediaType.APPLICATION_JSON})
	public String getHelloWorld()
	{
		return "hello World ! :)";
	}
	
	public POCEntity find(BigInteger id)
	{
	    return em.find(POCEntity.class, id);
	}
	
	public POCEntity createOrUpdateEntityPOC(POCEntity entity)
	{
		return this.em.merge(entity);
	}
	
	public void deleteEntityPOC(POCEntity entity)
	{
		this.em.remove(this.em.merge(entity));
	}
}
